/**
 * ...
 * @author Krzysztof Rozalski
 */

package hapi.unit;
import hapi.math.MathUtil;
import haxe.PosInfos;
import haxe.unit.TestCase;

class HapiTestCase extends TestCase {
	
	function assertFloatEqualsWithTolerance( expected:Float, actual:Float, ?c : PosInfos):Void {
		assertCondition(MathUtil.floatEquals(expected, actual), "expected " + expected + " but was " + actual, c);
	}
	
	function assertCondition(condition:Bool, ?printOnFail:String="test failed", ?c : PosInfos ) : Void {
		assertWithMessageAndThrow(condition, printOnFail, c);
	}
	
	function assertLessThan(less:Float, value:Float, ?c:PosInfos) {
		assertWithMessageAndThrow(less < value, "less than "+value+" expected ( is "+less+")", c);
	}
	
	function assertLessOrEqual(less:Float, value:Float, ?c:PosInfos) {
		assertWithMessageAndThrow(less <= value, "less or equals than "+value+" expected ( is "+less+")", c);
	}
	
	function assertMoreThan(more:Float, value:Float, ?c:PosInfos) {
		assertWithMessageAndThrow(more > value, "more than "+value+" expected ( is "+more+")", c);
	}
	
	function assertMoreOrEqual(more:Float, value:Float, ?c:PosInfos) {
		assertWithMessageAndThrow(more >= value, "more than "+value+" expected ( is "+more+")", c);
	}
	
	function assertWithMessageAndThrow( condition:Bool, printOnFail:String, c:PosInfos ):Void {
		currentTest.done = true;
		if (condition == false) {
			currentTest.success = false;
			currentTest.error = printOnFail;
			currentTest.posInfos = c;
			throw currentTest;
		}
	}
}